﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Systemet
{
    public partial class FlowController
    {
        private static FlowController instance;
        private TabPage startKort;
        private TabPage tabMeny;
        private TabControl tCmeny;
        private List<TabPage> mainTabView;
        private TabControl tcMainView;
        private FlowController() { }

        public static FlowController Instance
        {
            get 
            {
                if (instance == null)
                {
                    instance = new FlowController();
                }
                return instance;
            }
        }

        public List<TabPage> MainTabView
        {
            get { return mainTabView; }
            set { mainTabView = value; }
        }

        public TabControl TcMainView
        {
            get { return tcMainView; }
            set { tcMainView = value; }
        }

        public TabControl TCmeny
        {
            get { return tCmeny; }
            set { tCmeny = value; }
        }

        public TabPage TabMeny
        {
            get { return tabMeny; }
            set { tabMeny = value; }
        }

        public TabPage StartKort
        {
            get { return startKort; }
            set { startKort = value; }
        }

        public void StarSkarm()
        {
            if (!tcMainView.TabPages.Contains(startKort))
            {
                FlikRemover(startKort, tcMainView);
                tcMainView.TabPages.Add(startKort);
            }
        }

        //Sidomenyhanteraren
        public void SidMenyHandler(UserControl usercontrol)
        {

            if (!tCmeny.Controls.Contains(tabMeny))
            {
                FlikRemover(tabMeny, tCmeny);
                tabMeny.Controls.Clear();
                tabMeny.Controls.Add(usercontrol);
                tCmeny.Controls.Add(tabMeny);
            }

        }

        //Mainmenyhanteraren
        public void ShowSpecifikMenu(TabPage Mainview)
        {
            if (!tcMainView.Controls.Contains(Mainview))
            {
                FlikRemover(Mainview, tcMainView);
                tcMainView.Controls.Add(Mainview);
            }
        }

        private void FlikRemover(TabPage nuvarande, TabControl tcmeny)
        {
            foreach (TabPage tP in tcmeny.TabPages)
            {
                if (tP != nuvarande)
                {
                    tcmeny.TabPages.Remove(tP);
                    
                }
            }
        }

        //Uppstartshantering (borttagning av alla flikar)
        public void StartUpRemover()
        {
            foreach (TabPage tP in tCmeny.TabPages)
            {
                    tCmeny.TabPages.Remove(tP);
            }
            foreach (TabPage Tp in tcMainView.TabPages)
            {
                    tcMainView.TabPages.Remove(Tp);
            }
        }

        public UserControl getUserControl(TabPage aktuellMain)
        {
            UserControl tempUc = new UserControl();
            foreach(UserControl uC in aktuellMain.Controls)
            {
                tempUc = uC;
            }
            return tempUc;
        }
    }
}
